package com.goldsign.pay.web.portal;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;

/**@EnableFeignClients开启feiginClient功能*/
@EnableHystrix
@EnableHystrixDashboard
@EnableCircuitBreaker

@SpringBootApplication  
@EnableDiscoveryClient
@EnableFeignClients(basePackages={"com.goldsign.pay.web.portal.feign","com.goldsign.pay.feign.api"})
public class WebPortal {

    public static void main(String[] args) {
        SpringApplication.run(WebPortal.class,args);
    }
    
    /**初始化Hystrix.stream Servlet */
    @Bean
    public ServletRegistrationBean getServlet(){
      HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
      ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
      registrationBean.setLoadOnStartup(1);
      registrationBean.addUrlMappings("/hystrix.stream");
      registrationBean.setName("HystrixMetricsStreamServlet");
      return registrationBean;
    }
}
